1 using UnityEngine;
2 using
System.Collections;
3
4 [RequireComponent(
typeof(PhotonView))]
5 public
class ManualPhotonViewAllocator : MonoBehaviour
6 {
7     
public GameObject Prefab;
8
9     
public void AllocateManualPhotonView()
10     {
11         PhotonView pv =
this.gameObject.GetPhotonView();
12         
if (pv == null)
13         {
14             Debug.LogError(
"Can't do manual instantiation without PhotonView component.");
15             
return;
16         }
17
18         
int viewID = PhotonNetwork.AllocateViewID();
19         pv.RPC(
"InstantiateRpc", PhotonTargets.AllBuffered, viewID);
20     }
21
22     
[RPC]
23     
public void InstantiateRpc(int viewID)
24     {
25         GameObject go = GameObject.Instantiate(Prefab, InputToEvent.inputHitPos +
new Vector3(0, 5f, 0), Quaternion.identity) as GameObject;
26         go.GetPhotonView().viewID = viewID;
27
28         OnClickDestroy ocd = go.GetComponent<OnClickDestroy>();
29         ocd.DestroyByRpc =
true;
30     }
31 }



Trò chơi Tic-Tac-Toe, game đánh caro full source code 53.580 lượt xem

Gõ tìm kiếm nhanh...